import 'package:flutter/material.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

import '../../../helper/utils/util.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);
  final controller = Get.put(HomeController());
  // 主视图
  Widget _buildView() {
    return SmartRefresher(
      controller: controller.state.rc,
      onRefresh: controller.onRefresh,
      child: GridView.builder(
        gridDelegate:
            SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
        itemBuilder: (ctx, idx) {
          var md = controller.state.list[idx];
          return HomeCell(
            md: md,
            onTap: () => controller.goUrl(md),
          );
        },
        itemCount: controller.state.list.length,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: const Text("企明星各项目盒装"),
            centerTitle: true,
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
